//
//  ItemView.m
//  ssss
//
//  Created by 周成龙 on 17/5/8.
//  Copyright © 2017年 ZCL. All rights reserved.
//

#import "ItemView.h"

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height

@implementation ItemView  {
    UIScrollView *_scrollView;
    UIImageView *_imageV;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.frame = self.bounds;
        _scrollView.backgroundColor = [UIColor redColor];
        _scrollView.delegate = self;
        _scrollView.minimumZoomScale = 1.0;
        _scrollView.maximumZoomScale = 2.0;
        [self addSubview:_scrollView];
        
        _imageV = [[UIImageView alloc] init];
        _imageV.frame = _scrollView.bounds;
        _imageV.userInteractionEnabled = YES;
        [_scrollView addSubview:_imageV];
    }
    return self;
}
    
- (void)setImage:(UIImage *)image {
    _imageV.image = image;
}
    
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    NSLog(@"scrollViewDidZoom");
    
    if (scrollView.zoomScale > 1.0) {// 放大
        NSLog(@"放大");
    }else {
        NSLog(@"缩小");
    }
}

- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

    for (UIView *view in _scrollView.subviews) {
        if ([view isKindOfClass:[UIImageView class]]) {
            return view;
        }
    }
    return nil;
}
    
@end
